package cate.common.table.activity.heroreplace.sheet;

import cate.common.table.ESheet;
import cate.common.table.activity.heroreplace.row.HeroReplaceGroupRow;
import cate.common.util.random.RWList;

import java.util.List;
import java.util.stream.Collectors;

public class HeroReplaceGroupSheet extends ESheet<HeroReplaceGroupRow> {
    @Override
    public String getSheetName() {
        return "置换池";
    }

    public HeroReplaceGroupRow random(int group, int heroTid) {
        HeroReplaceGroupRow heroGroupRow = getList().stream().filter(e -> e.group == group && e.heroTid == heroTid).findAny().orElse(null);
        if (heroGroupRow == null) {
            return null;
        }
        List<HeroReplaceGroupRow> list = getList().stream().filter(e -> e.heroGroup == heroGroupRow.heroGroup && e.heroTid != heroTid).collect(Collectors.toList());
        if (list.isEmpty()) {
            return null;
        }
        RWList<HeroReplaceGroupRow> rwList = new RWList<>();
        rwList.addAndSetup(list);
        return rwList.get();
    }
}
